<template>
	<view class="contain">
			<u--form labelPosition="left" label-width="90px" :rules="rules" ref="uForm" >
				<u-form-item label="新密码" borderBottom ref="item1">
					<view class="flex justify-start">
						<view><u--input type="password" v-model="apply.newpwd" placeholder="请输入新密码" border="surround"></u--input></view>						
					</view>
				</u-form-item>
				<u-form-item label="确认密码" borderBottom ref="item1">
					<view class="flex justify-start">
						<view><u--input type="password" v-model="apply.compwd" placeholder="确认密码" border="surround"></u--input></view>					
					</view>
				</u-form-item>
			</u--form>
			
			<view class="mt-8">
				<!-- <view class="submit" @submit.prevent="submitinfo">提交</view> -->
				<u-button type="primary" @click="submitinfo" text="确定"></u-button>
			</view>
			
	</view>
</template>

<script setup lang='ts'>
import { ref,reactive } from 'vue'
import {  onLoad,onShow } from '@dcloudio/uni-app'
import {Date_EE} from '@/common/date.js'
import { userStore } from '@/stores/userStore'

let store = userStore();	
let { hasLogin,userData } = userStore();



let cshow=ref(false);
let show=ref(false);

let apply=reactive({
	newpwd:'',
	compwd:''
});

const rules=reactive({});



const selectClick=(e:any)=>{
	console.log("选择课程:",e);
}


//页面加载
onLoad(()=>{

});
onShow(()=>{
	console.log("是否已登录",hasLogin);
	if(userData.userinfo.id!=null && userData.userinfo.id!=""){
		hasLogin=true;
	}else{
		uni.$tools.Toast("请登录后访问");
		setTimeout(()=>{
			store.$state.backRouter="/mine/resetpwd/resetpwd";
			uni.$tools.GoUrl('/pages/login/login');
		},1000);
	}	
});

let uForm=ref<any>();
const checkLogin=()=>{
	if(!hasLogin){
		uni.showModal({
			title:"请登录后操作",
			showCancel:true,
			success:res=>{
				if(res.confirm){
					uni.$tools.GoUrl("/pages/login/login");
				}
			}
		})
		return false;
	}	
	return true;
}
const submitinfo=()=>{
	
	if(!/\S/.test(apply.newpwd)){
		uni.$tools.Toast("请输入新密码")
		return false;
	}
	if(!/\S/.test(apply.compwd)){
		uni.$tools.Toast("请确认密码")
		return false;
	}	
	if(apply.compwd!=apply.newpwd){
		uni.$tools.Toast("两次密码输入不一致")
		return false;
	}
	console.log("提交的信息:",apply);
	let paraData={
		id:userData.userinfo.id,
		logpwd:apply.compwd
	}
	console.log("修改密码参数:",paraData);
	uni.$tools.Reqeust('/api/updatePassword',paraData,'POST').then((res:any)=>{
		console.log('预约返回:==>',res);
		if (res.data.code == 200) {
			uni.$tools.Toast("修改成功");
			setTimeout(()=>{
				uni.$tools.GoUrl("/pages/mine/mine",2);
			},1500);
		}
	})
	return false;
}



</script>
<style>
	:deep(input){
		/* border:1px solid red; */
		width:200px !important;
	}
</style>
<style lang='scss' scoped>
	@import "resetpwd.scss";
</style>